//
//  OPNoteMapViewController.m
//  OnePiece
//
//  Created by lanou on 15/10/30.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPNoteMapViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "OPAnnotation.h"
#import "OPNoteAnnotionView.h"


@interface OPNoteMapViewController () <MKMapViewDelegate>
@property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) NSMutableArray *dataSourceArray;
@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, assign) NSMutableArray *locationArray;
@property (nonatomic, strong) MKPolyline *routeLine;

@end

@implementation OPNoteMapViewController

- (NSMutableArray *)dataSourceArray
{
    if (_dataSourceArray == nil) {
        self.dataSourceArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataSourceArray;
}

- (NSMutableArray *)locationArray
{
    if (!_locationArray) {
        self.locationArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _locationArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _mapView.delegate = self;
    [self.view addSubview:_mapView];

    for (NSDictionary *dic in self.pathMapArray) {
        OPAnnotation *anno = [[OPAnnotation alloc]init];
        anno.coordinate = CLLocationCoordinate2DMake([dic[@"x"] doubleValue], [dic[@"y"] doubleValue]);
        anno.icon = @"iconfont-place";
        [_mapView addAnnotation:anno];
    }
    
    _backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _backBtn.frame = CGRectMake(20, 40, 40, 30);
    _backBtn.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.502];
    _backBtn.layer.cornerRadius = 5;
    [_backBtn setImage:[UIImage imageNamed:@"zyciconfont-houtui"] forState:(UIControlStateNormal)];
    [_backBtn addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_backBtn];
    
    

}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(OPAnnotation *)annotation
{
    OPNoteAnnotionView *annoView = (OPNoteAnnotionView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"anno"];
    if (annoView == nil) {
        annoView = [[OPNoteAnnotionView alloc]initWithAnnotation:nil reuseIdentifier:@"anno"];
    }
    annoView.image = [UIImage imageNamed:@"iconfont-place (1)"];
    annoView.annotation = annotation;

    return annoView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
